package com.vecspace.sso.entity;

import java.io.Serializable;

/** 功能及授权类型(不带children属性) */
public class AppFuncAuth implements Comparable<AppFuncAuth>,Serializable{
	
	private static final long serialVersionUID = 2522618686848537448L;

	private Long funcId;
	
	private AppFunction func;
	
	private int authType = 0;
			
	public Long getFuncId() {
		if(funcId == null) {
			if(func != null) {
				return func.getId();
			}
		}
		return funcId;
	}
	
	public void setFuncId(Long funcId) {
		this.funcId = funcId;
	}
	
	public Long getParentId() {
		if(func == null)return -1L;
		return func.getParentId();
	}
	
	public AppFunction getFunc() {
		return func;
	}
	public void setFunc(AppFunction func) {
		if(func != null) {
			funcId = func.getId();
		}
		this.func = func;
	}
	public int getAuthType() {
		return authType;
	}
	public void setAuthType(Integer authType) {
		if(authType == null) {
			this.authType = 0;
		}else {
			this.authType = authType;
		}
	}
	
	@Override
	public boolean equals(Object obj) {
		if(obj == null)return false;
		if(funcId == null)return false;
		AppFuncAuth oth = (AppFuncAuth)obj;
		return funcId.equals(oth.funcId);
	}
	
	@Override
	public int hashCode() {
		if(funcId == null)return 0;
		return funcId.hashCode();
	}

	@Override
	public int compareTo(AppFuncAuth oth) {
		if(oth == null)return -1;//空值排在后面
		if(oth.func == null)return -1;
		if(oth.func.getOrdnum() == null)return -1;
		
		if(func == null)return 1;
		if(func.getOrdnum() == null)return 1;
		
		return func.getOrdnum().compareTo(oth.getFunc().getOrdnum());
	}
}
